package com.ciaojian.core.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ciaojian.core.model.WorkerAuthority;
import com.ciaojian.core.model.vo.AuthorityGroupVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 
 * @since 2022-07-06
 */
public interface WorkerAuthorityMapper extends BaseMapper<WorkerAuthority> {


    List<AuthorityGroupVo> getAuthorityGroup(@Param("workerId") Integer workerId, @Param("type") Integer type);

    @Select(" SELECT worker_id   AS workerId,\n" +
            "               CONCAT('[',\n" +
            "                      GROUP_CONCAT(CONCAT('{', '\\\"id\\\":', store_id, ',', '\\\"title\\\":', '\\\"', ds.title, '\\\"}') SEPARATOR\n" +
            "    ','),\n" +
            "                      ']') AS storeIds\n" +
            "        FROM d_worker_authority AS dwa\n" +
            "                 LEFT JOIN d_store AS ds ON ds.id = dwa.store_id\n" +
            "        WHERE dwa.`status` = 1\n" +
            "          AND dwa.`type` = #{type}\n" +
            "          AND dwa.worker_id = #{workerId}\n" +
            "        GROUP BY worker_id")
    List<AuthorityGroupVo> getAuthorityGroupfran(Integer workerId, Integer type);
}
